package fun.taostool.mapper;

import fun.taostool.vo.RtDataVo;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class RtDataRowMapper implements RowMapper<RtDataVo> {

    @Override
    public RtDataVo mapRow(ResultSet rs, int num) throws SQLException {
        //从结果集里把数据得到
        long ts = rs.getLong("last_row(ts)");
        String id = rs.getString("tbname").replaceAll("_", ".");
        String value = rs.getString("last_row(value)");
        long aste = rs.getLong("last_row(aste)");
        long qulity = rs.getLong("last_row(qul)");
        //把数据封装到对象里
        RtDataVo rtDataVo = new RtDataVo();

        rtDataVo.setTm(ts);
        rtDataVo.setPv(value);
        rtDataVo.setAste(aste);
        rtDataVo.setQul(qulity);
        rtDataVo.setLocationCode(id.substring(0, id.indexOf(".")));
        rtDataVo.setTag(id.substring(id.indexOf(".") + 1));
        rtDataVo.setId(id);
        return rtDataVo;

    }
}